package com.alibaba.citrus.ots.platform.enhance.functions.diff.sap.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.SalesOrderLineDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser.DataParser;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.otsapplicationadaptersdk.sap.MnSapIf015Detail;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hanguo
 * @date 2022/1/24
 * @Description 请填写描述信息
 */
@Component
public class SapIf015DetailDataParse extends DataParser {


    /**
     * 日志
     */
    private static Log log = Log.getLogger(SapIf015DetailDataParse.class);

    /**
     * sap报文字段，映射成对账处理的业务字段(标准字段)
     * key：sap报文中的字段，value：转换后的字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> sapDataFiledMapping = new HashedMap();

    static {
        sapDataFiledMapping.put("orderLineId", SalesOrderLineDiffStandardFieldDict.SERIAL_NUMBER.getFieldCode());
        sapDataFiledMapping.put("outOrderLineId",SalesOrderLineDiffStandardFieldDict.SAP_SALES_ORDER_LINE_ID.getFieldCode());
        sapDataFiledMapping.put("scItemId",SalesOrderLineDiffStandardFieldDict.ITEM_ID.getFieldCode());
        sapDataFiledMapping.put("quantity",SalesOrderLineDiffStandardFieldDict.ITEM_QUANTITY.getFieldCode());
        sapDataFiledMapping.put("saleUnit",SalesOrderLineDiffStandardFieldDict.SALE_UNIT.getFieldCode());

        //需要*100进行转换
        sapDataFiledMapping.put("price",SalesOrderLineDiffStandardFieldDict.UNIT_PRICE.getFieldCode());
        sapDataFiledMapping.put("activityPrice",SalesOrderLineDiffStandardFieldDict.SPECIAL_OFFER_PRICE.getFieldCode());
        sapDataFiledMapping.put("subTotalAmount",SalesOrderLineDiffStandardFieldDict.SUB_TOTAL_AMOUNT.getFieldCode());

        sapDataFiledMapping.put("returnFlag",SalesOrderLineDiffStandardFieldDict.RETURN_FLAG.getFieldCode());
        sapDataFiledMapping.put("closeCode",SalesOrderLineDiffStandardFieldDict.REFUSE_REASON_CODE.getFieldCode());
        //sapDataFiledMapping.put("closeReason",SalesOrderLineDiffStandardFieldDict.REFUSE_REASON_NAME.getFieldCode());

    }

    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof MnSapIf015Detail) {
            MnSapIf015Detail mnSapIf015Detail = (MnSapIf015Detail) obj;
            return obtainFieldLineMap(sapDataFiledMapping, mnSapIf015Detail, mnSapIf015Detail.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "MnSapIf015Detail";
    }
}
